#ifndef TRIE_H
#define TRIE_H

#pragma once
#include "file_class.h"

class TrieNode
{

public:
    QChar value;
    bool isEndOfWord;
    QVector<FileInfo> files;
    QMap<QChar, QSharedPointer<TrieNode>> children;

public:
    TrieNode();
    TrieNode(QChar Value);
    TrieNode(QChar Value, bool Judge, FileInfo File);

};

class Trie
{

private:
    QSharedPointer<TrieNode> root;

public:
    Trie();

public:
    void Insert(const QString& str, const FileInfo& file);
    void InsertWithSuffix(const QString& str, const FileInfo& file);
    void collectWords(QSharedPointer<TrieNode> node, QVector<FileInfo>& result);
    QSharedPointer<TrieNode> GetRoot();

public:
    //不区分大小写的搜索|前缀搜索
    QVector<FileInfo> TrueSearchIgnoreCase(const QString& str, int index, QSharedPointer<TrieNode> node);
    QVector<FileInfo> SearchIgnoreCase(const QString& str);
    QVector<FileInfo> TruePrefixSearchIgnoreCase(const QString& prefix, int index, QSharedPointer<TrieNode> node);
    QVector<FileInfo> PrefixSearchIgnoreCase(const QString& prefix);
    //区分大小写的搜索|前缀搜索
    QVector<FileInfo> Search(const QString& str);
    QVector<FileInfo> PrefixSearch(const QString& prefix);
    //模糊匹配搜索
    QVector<FileInfo> FuzzySearch(const QString& str, int maxCost);
    QVector<FileInfo> FuzzyPrefixSearch(const QString& prefix, int maxCost);

};

int getMaxCost(const QString& input);

#endif // TRIE_H
